package cn.madis.ymcc.service.impl;

import cn.madis.ymcc.service.ITokenCreatorService;
import cn.madis.ymcc.util.StrUtils;
import cn.madis.ymcc.utils.LoginSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;
@Service
public class TokenCreatorServiceImpl implements ITokenCreatorService {
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    /**
     * 生成token防止重复订单
     * @param courseId
     * @return
     */
    @Override
    public String selectById(String courseId) {
        Long loginId = LoginSecurityContext.getLoginJwtDtoContext().getId();
        String key = loginId + ":" + courseId;
        //token
        String randomString = StrUtils.getRandomString(6);
        redisTemplate.opsForValue().set(key,randomString,10, TimeUnit.MINUTES);
        return randomString;
    }
}
